package cn.com.easy.permission.service.init;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import cn.com.easy.permission.dao.UserDao;
import cn.com.easy.permission.model.UserModel;
import cn.com.easy.utils.SecurityUtils;

/**
 * system init service
 * 
 * @author nibili 2014-12-21
 */
@Service
@Lazy(false)
public class SystemInitService {

	/** user infomation dao */
	@Autowired
	private UserDao userDao;

	@PostConstruct
	public void init() {
		UserModel userModel = userDao.findByLoginname("admin");
		if (userModel == null) {
			// if the user admin is null , then insert admin user to database.
			userModel = new UserModel();
			userModel.setLoginname("admin");
			userModel.setPassword(SecurityUtils.SHA256Normal(SecurityUtils.SHA256Normal("123456")));
			userModel.setEmail("196888813@qq.com");
			userDao.save(userModel);
		}
	}
}
